package shujujiegou.Duigui;
/*递归版本的冒泡排序*/

public class BubbleSort {

    public static void sort(int []a){
        bubble(a,a.length);
    }

    private static void bubble(int []a,int j){
        if (j==0){
            return;
        }
        int x=0;//减少范围，减少内存消耗
        for (int i = 0; i < j; i++) {
            if (a[i]>a[i+1]){
                int t=a[i];
                a[i]=a[i+1];
                a[i+1]=t;
                x=i;
            }
        }
        bubble(a,x);
    }
}
